package com.taotao.web.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.JsonNode;
import com.taotao.common.httpclinet.HttpResult;
import com.taotao.common.service.ApiService;
import com.taotao.web.bean.Order;
import com.taotao.web.bean.User;
import com.taotao.web.threadlocal.UserThreadLocal;

@Service
public class OrderService {
	@Autowired
	private ApiService apiService;
	@Value("${ORDER_TAOTAO_BASE_URL}")
	public String ORDER_TAOTAO_BASE_URL;
	
	public String submit(Order order) {
		String url = ORDER_TAOTAO_BASE_URL+"/order/create";
		try {
			HttpResult httpResult = this.apiService.doPostJson(url, UserService.MAAPER.writeValueAsString(order));
			if (httpResult.getCode().intValue()==200) {//http响应状态码
				JsonNode jsonNode = UserService.MAAPER.readTree(httpResult.getData());
				if (jsonNode.get("status").intValue()==200) {//业务状态吗
					//订单提交成功,返回订单号
					return jsonNode.get("data").asText();
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
